package net.softwarefabrik.bde.core.model.platform;

import java.util.ArrayList;
import java.util.Collection;

import net.softwarefabrik.bde.core.model.BDEConstants;
import net.softwarefabrik.bde.core.model.BDEException;

/**
 * The configuration data which is used by a <code>PlatformProvider</code> to
 * generate a platform specific configuration at runtime.
 * 
 * Mandatory <code>PlatformConfiguration</code> options:
 * <ol>
 * <li>- versionInfo</li>
 * <li>- workingDirectory</li>
 * </ol>
 * 
 * @author Matthias Kuespert
 */
public final class PlatformConfiguration {

    /**
     * The default start level.
     */
    public static final int        DEFAULT_PLATFORM_START_LEVEL = 10;

    /**
     * The default bundle start level.
     */
    public static final int        DEFAULT_BUNDLE_START_LEVEL   = 5;

    private PlatformVersionInfo    versionInfo                  = null;

    private int                    platformStartLevel           = DEFAULT_PLATFORM_START_LEVEL;

    private int                    defaultBundleStartLevel      = DEFAULT_BUNDLE_START_LEVEL;

    private Collection<BundleInfo> bundles                      = new ArrayList<BundleInfo>();

    private String                 workingDirectory             = null;

    private boolean                clearWorkspace               = false;

    public PlatformConfiguration(PlatformVersionInfo versionInfo, String workingDirectory) throws BDEException {
        if (null == versionInfo) {
            throw new BDEException("No PlatformVersionInfo specified when creating PlatformConfiguration");
        }
        if (null == workingDirectory || BDEConstants.EMPTY_STRING.equals(workingDirectory)) {
            throw new BDEException("No working directory specified when creating PlatformConfiguration");
        }
        //
        this.versionInfo = versionInfo;
        this.workingDirectory = workingDirectory;
    }

    /**
     * @return the defaultBundleStartLevel
     */
    public final int getDefaultBundleStartLevel() {
        return defaultBundleStartLevel;
    }

    /**
     * @param defaultBundleStartLevel the defaultBundleStartLevel to set
     */
    public final void setDefaultBundleStartLevel(int defaultBundleStartLevel) {
        this.defaultBundleStartLevel = defaultBundleStartLevel;
    }

    /**
     * @return the platformStartLevel
     */
    public final int getPlatformStartLevel() {
        return platformStartLevel;
    }

    /**
     * @param platformStartLevel the platformStartLevel to set
     */
    public final void setPlatformStartLevel(int platformStartLevel) {
        this.platformStartLevel = platformStartLevel;
    }

    /**
     * @return the bundles
     */
    public final Collection<BundleInfo> getBundles() {
        return bundles;
    }

    /**
     * @param bundles the bundles to set
     */
    public final void setBundles(Collection<BundleInfo> bundles) {
        this.bundles = bundles;
    }

    /**
     * @return the working directory in which the platform should be started.
     */
    public final String getWorkingDirectory() {
        return workingDirectory;
    }

    /**
     * @return the clearWorkspace setting
     */
    public final boolean doClearWorkspace() {
        return clearWorkspace;
    }

    /**
     * @param clearWorkspace the clearWorkspace to set
     */
    public final void setClearWorkspace(boolean clearWorkspace) {
        this.clearWorkspace = clearWorkspace;
    }

    /**
     * @return The <code>PlatformVersionInfo</code> object which provides
     *         information about the concrete platform version that should be
     *         used.
     */
    public final PlatformVersionInfo getVersionInfo() {
        return versionInfo;
    }
}
